﻿<?php
session_start();
function deldir($dir) {
  //先删除目录下的文件：
  $dh=opendir($dir);
  while ($file=readdir($dh)) {
    if($file!="." && $file!="..") {
      $fullpath=$dir."/".$file;
      if(!is_dir($fullpath)) {
          unlink($fullpath);
      } else {
          deldir($fullpath);
      }
    }
  }
 
  closedir($dh);
  //删除当前文件夹：
  if(rmdir($dir)) {
    return true;
  } else {
    return false;
  }
}
echo '<body bgcolor="#009900"><center><h2>删除目录</h2>';
if(isset($_SESSION["user"])==false){
	header("location:../login.php");
	exit;
}
$user=$_SESSION["user"];
if(isset($_SESSION["dir"])==false){
	header("location:index.php");
	exit;
}
$dir=$_SESSION["dir"];
$name=$_POST["name"];
$name=str_ireplace("..","isnot",$name);
$name=str_ireplace(";","isnot",$name);
deldir("$user/$dir/$name");

$file=fopen("../log.txt","a");
include '../lib/time.php';
fwrite($file,"\r\n" . $time . ":'$user' in '$dir' delete dir '$name'.");


header("location:index.php?dir=$dir");
exit;
?>